package leetcode.code1686;

import java.util.Arrays;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int stoneGameVI(int[] aliceValues, int[] bobValues) {
		int len = bobValues.length;
		int[][] vals = new int[len][2];
		for (int i = 0; i < vals.length; i++) {
			int a = aliceValues[i], b = bobValues[i];
			vals[i][0] = a + b;// Math.abs(a - b);
			vals[i][1] = i;
		}
		Arrays.sort(vals, (a, b) -> b[0] - a[0]);
		Integer a = 0, b = 0;
		for (int i = 0; i < vals.length; i++) {
			if ((i & 1) == 0) {
				a += aliceValues[vals[i][1]];
			} else {
				b += bobValues[vals[i][1]];
			}
		}
		return a.compareTo(b);
	}

	@Override
	public void debug4() {
		H.compare(1, this.stoneGameVI(H.str2array3("[9,8,3,8]"), H.str2array3("[10,6,9,5]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {
		// TODO Auto-generated method stub

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
